﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSharpAlgorithm
{
    class BuildTheFence
    {
        public BuildTheFence()
        {
            int testCase = Int32.Parse(TestConsole.ReadLine());
            while (testCase-- > 0)
            {
                TestConsole.ReadLine();
                int sheepCount = Int32.Parse(TestConsole.ReadLine());
                List<SheepPoint> pointList = new List<SheepPoint>();
                int minX = Int32.MaxValue, minY = Int32.MaxValue;
                int botP = 0;
                //입력
                for (int i = 0; i < sheepCount; i++)
                {
                    string[] input = TestConsole.ReadLine().Split(' ');
                    int x = Int32.Parse(input[0]);
                    int y = Int32.Parse(input[1]);
                    pointList.Add(new SheepPoint(i + 1, x, y));
                    minX = Math.Min(x, minX);
                    if (y < minY)
                    {
                        minY = y;
                        botP = pointList.Count - 1;
                    }
                    else if ( y == minY)
                    {
                        if (pointList[botP].x > pointList[pointList.Count - 1].x)
                        {
                            minY = y;
                            botP = pointList.Count - 1;
                        }
                    }
                }
                //각도 정렬
                int offsetX = (minX < 0) ? minX : 0;
                int offsetY = (minY < 0) ? minY : 0;
                SheepPoint first = pointList[botP];
                first.deg = 0;
                first.x -= offsetX;
                first.y -= offsetY;
                pointList.RemoveAt(botP);
                int[] degArray = new int[100000];
                for (int i = 0; i < pointList.Count; i++)
                {
                    pointList[i].x -= offsetX;
                    pointList[i].y -= offsetY;
                    pointList[i].deg = Math.Atan2(pointList[i].y - first.y, pointList[i].x - first.x);
                    pointList[i].xdef = Math.Abs(pointList[i].x - first.x);
                    int hash = Hash(pointList[i].deg);
                    HashAdd(degArray, hash, pointList, i);
                }
                pointList.Insert(0, first);
                List<SheepPoint> orderList = new List<SheepPoint>();
                for (int i = 0; i < degArray.Length; i++)
                {
                    if (degArray[i] > 0)
                    {
                        orderList.Add(pointList[degArray[i]]);
                    }
                }
                //최외각 스택 생성
                Stack<int> stack = new Stack<int>();
                stack.Push(0);
                stack.Push(1);
                stack.Push(2);
                for (int i = 3; i < orderList.Count; i++)
                {
                    int b = stack.Pop();
                    int a = stack.Pop();
                    int c = i;
                    int v = CCW(orderList[a], orderList[b], orderList[c]);
                    if (v <= 0)
                    {
                        stack.Push(a);
                        stack.Push(c);
                    }
                    else
                    {
                        stack.Push(a);
                        stack.Push(b);
                        stack.Push(c);
                    }
                }
                //list로 변환
                List<int> pense = new List<int>();
                while (stack.Count > 0)
                {
                    int i = stack.Pop();
                    if (i < orderList.Count)
                    {
                        pense.Insert(0, i);
                    }
                }
                if (orderList.Count >= 3 && CCW(orderList[0], orderList[1], orderList[2]) == 0)
                {
                    pense.RemoveAt(1);
                }
                //출력
                StringBuilder result = new StringBuilder();
                double length = 0;
                for (int i = 0; i < pense.Count - 1; i++)
                {
                    length += GetLength(orderList[pense[i]], orderList[pense[i + 1]]);
                    result.Append(orderList[pense[i]].id + " ");
                }
                length += GetLength(orderList.Last(), orderList[0]);
                result.Append(orderList.Last().id);
                Console.WriteLine(length.ToString("F2"));
                Console.WriteLine(result);
                Console.WriteLine();
            }
        }
        private void HashAdd(int[] degArray, int hash, List<SheepPoint> pointList, int index)
        {
            
            if (degArray[hash] == 0)
            {
                degArray[hash] = index + 1;
            }
            else if (pointList[degArray[hash]].deg == pointList[index].deg)
            {
                if (pointList[degArray[hash]].xdef > pointList[index].xdef)
                {
                    degArray[hash] = index + 1;
                }
            }
            else if (pointList[degArray[hash]].deg > pointList[index].deg)
            {
                HashAdd(degArray, hash + 1, pointList, index);
            }
            else
            {
                HashAdd(degArray, hash - 1, pointList, index);
            }
        }
        private int Hash(double deg)
        {
            //0~3.15 -> 0~100000
            return (int)deg * 31746;
        }
        private double GetLength(SheepPoint p1, SheepPoint p2)
        {
            double length = Math.Sqrt((p2.x - p1.x) * (p2.x - p1.x) + (p2.y - p1.y) * (p2.y - p1.y));
            return length;
        }
        private int CCW(SheepPoint p1, SheepPoint p2, SheepPoint p3)
        {
            return (p2.x - p1.x) * (p3.y - p1.y) - (p2.y - p1.y) * (p3.x - p1.x);
        }
    }

    class SheepPoint
    {
        public int id { get; set; }
        public int x { get; set; }
        public int y { get; set; }
        public double deg { get; set; }
        public int xdef { get; set; }
        public int hash { get; set; }
        public SheepPoint(int id, int x, int y)
        {
            this.id = id;
            this.x = x;
            this.y = y;
        }
    }
}
